home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.03 Mar 94 / Fixed Point Math / Source / Transformations.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-29  |  1.3 KB  |  62 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * 
  3.  * Transformations.c
  4.  * Transformations: Rotation of points in 3-D space.
  5.  * Abridged version for MacTech
  6.  * (Matrix transformations omitted)
  7.  *
  8.  * Alexei Lebedev, October 6, 1992
  9.  *
  10.  *****/
  11.   
  12. #include "Transformations.h"
  13. #include "SineTable.h"
  14. #include "FixedPointMath.h"
  15.  
  16. /* ------------------------------ */
  17.  
  18. void ScalePoint(Vector3D *p, Fixed x, Fixed y, Fixed z)
  19. {    
  20.     p->x = Multiply(p->x, x);
  21.     p->y = Multiply(p->y, y);
  22.     p->z = Multiply(p->z, z);
  23. }
  24.  
  25. /* ------------------------------ */
  26.  
  27. void PitchPoint(Vector3D *p, short angle)
  28. {
  29.     Fixed sin, cos, yPrime, zPrime;
  30.     
  31.     GetTrigValues(angle, &sin, &cos);
  32.     yPrime = Multiply(p->y, cos) - Multiply(p->z, sin);
  33.     zPrime = Multiply(p->y, sin) + Multiply(p->z, cos);
  34.     p->y = yPrime;
  35.     p->z = zPrime;
  36. }
  37.  
  38. /* ------------------------------ */
  39.  
  40. void YawPoint(Vector3D *p, short angle)
  41. {
  42.     Fixed sin, cos, xPrime, zPrime;
  43.     
  44.     GetTrigValues(angle, &sin, &cos);
  45.     xPrime = Multiply(p->x, cos) + Multiply(p->z, sin);
  46.     zPrime = -Multiply(p->x, sin) + Multiply(p->z, cos);
  47.     p->x = xPrime;
  48.     p->z = zPrime;
  49. }
  50.  
  51. /* ------------------------------ */
  52.  
  53. void RollPoint(Vector3D *p, short angle)
  54. {
  55.     Fixed sin, cos, xPrime, yPrime;
  56.     
  57.     GetTrigValues(angle, &sin, &cos);
  58.     xPrime = Multiply(p->x, cos) - Multiply(p->y, sin);
  59.     yPrime = Multiply(p->x, sin) + Multiply(p->y, cos);
  60.     p->x = xPrime;
  61.     p->y = yPrime;
  62. }